package com.intelap.rp3.coherence.pruebaConcepto;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Logger;

import com.tangosol.io.nio.MappedBufferManager;
import com.tangosol.io.nio.MappedStoreManager;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.DefaultCacheServer;
import com.tangosol.net.NamedCache;
import com.tangosol.util.MapEvent;
import com.tangosol.util.MapListener;

public class Servidor {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final Logger log = Logger.getLogger("Servidor-"+args[0]);
		
		// DefaultCacheServer.main(args);
		if (true) {
			DefaultCacheServer
					.start(CacheFactory.getConfigurableCacheFactory());
			
			NamedCache itemsCache = CacheFactory.getCache("cacheDeAlmacen");
			itemsCache.addMapListener(new MapListener() {

				@Override
				public void entryDeleted(MapEvent evt) {
					log.info("Entry deleted: " + evt.getOldEntry().getKey()
							+ ", " + evt.getOldEntry().getValue());
				}

				@Override
				public void entryInserted(MapEvent evt) {
					log.info("Entry inserted: " + evt.getNewEntry().getKey()
							+ ", " + evt.getNewEntry().getValue());
				}

				@Override
				public void entryUpdated(MapEvent evt) {
					log.info("Entry updated: " + evt.getOldEntry().getKey()
							+ ", " + evt.getOldEntry().getValue() + " -> "
							+ evt.getNewEntry().getKey()
							+ ", " + evt.getNewEntry().getValue());
				}

			});

		}
		
		try {
			while (true) {
				Object monitor = new Object();
				synchronized (monitor) {
					monitor.wait();
					log.info("Fui despertada. A dormir otra vez");
				}
			}
		} catch (InterruptedException e) {
			DefaultCacheServer.shutdown();
		}
	}

}
